﻿using System;
using System.IO;
using System.Collections.Generic;
//###HEADER###
//Title: RevitPlus
//Description of Program: Utilzing Revit geometry and properties, user is able to perform an EnergyPlus calculation within Revit.
//Class:GetEplusVersions
//Description of Class: Determines which version of EnergyPlus the user has. If none, an error is given.    
//       
//By: Steve Chick & Alexander Bernstein
//Date: 12/18/2012
//Version: 001

using System.Linq;
using System.Text;
using Microsoft.Win32;
using System.Windows.Forms;
using System.Reflection;
using System.Globalization;
using System.Diagnostics;
using System.Runtime.InteropServices;

using Autodesk.Revit;
using Autodesk.Revit.UI;

namespace Revit_Addin1
{
    //Define Class
    public class GetEplusVersions
    {
        public static void get()
        {
            //Clear all previous values in the list
            StoredVariables.EPlusVersions.Clear();

            //Place all folders in the C:\ Directory in a list
            string[] paths = Directory.GetDirectories(@"C:\");

            List<String> versions = new List<string>();

            //Filter the list for all strings containing EnergyPlus
            foreach (string s in paths)
            {
            if (s.Contains("EnergyPlus"))
            {
                versions.Add(s);
            }
            }

            //Check for EnergyPlus versions
            if (versions != null)
            {
                //Format strings correctly
                foreach (string str in versions)
                {
                    string newstr = str;
                    newstr = newstr.Remove(0, 13);
                    newstr = newstr.Replace("\\", "");
                    StoredVariables.EPlusVersions.Add(newstr);
                }
            }
            //Alert the user if no versions of EnergyPlus can be found
            else
            {
                TaskDialog.Show("ERROR","No Versions of EnergyPlus found in the C:\\ Directory",TaskDialogCommonButtons.Ok);
            }
        }
    }
}